<?php
	
	/**
   * manage-programs is used as a starting point for viewing, editing, and adding new programs.
   * A program consists of a Name, Year, Code, Semester, and fees for Application, Interview, and Tuition
   *
   * @Author Tyler Bradovich
   */
   
    @session_start();
    require_once 'shared-functions.php';
    require_once 'session.php';
    require_once 'masterpage.php';
    
    if(!IsValidSession())
    {
        header('Location: login.php?page=manage-programs');
        exit();
    }
    else
    {
    	RefreshSession();
    }

	$user = GetCurrentUserAccessLevel();
	
    //Check user access
    if($user != $DIRECTOR && $user != $ADMIN && $user != $PRINCIPLE)
    {
        header('Location: login.php?page=manage-programs&error=To access to the manage programs page, please log in as a director, principle or admin&logout=1');
        exit();
    }
	
    masterpage("Manage Programs");
	
	echo "<a href='add-program.php'>Add New Program</a><br/><br/>";

    $link = connect_db();
    $query = "SELECT `ProgramID`, `Name`, `Year`, `Code`, `Semester`, `ApplicationFee`, `InterviewFee`, `TuitionFee` FROM `Program`";
    $courses = mysql_query($query,$link);
    if(!$courses)
    {
        echo "Oops...something went wrong. Please contact support.";
        exit();
    }
	
    echo "<table class='DataList'>";
    echo "  <thead>";
    echo "    <tr><th class='header'> </th><th class='header'>Name</th><th class='header'>Year</th><th class='header'>Code</th><th class='header'>Semester</th>";
	echo "	  <th class='header'>Application Fee</th><th class='header'>Interview Fee</th><th class='header'>School Fees</th></tr>";
    echo "  </thead>";
    echo "  <tbody>";

	$rowID = 0;
    while($tblrow = mysql_fetch_array($courses,MYSQL_BOTH))
    {
	  if ($rowID == 0)
	  {
		$rowClass = "rows";
		$rowID++;
	  }
	  else
	  {
		$rowClass = "altrows";
		$rowID--;
	  }
	  echo "<form action='edit-program.php' method='POST'>";
	  echo "<input type='hidden' name='id' value='$tblrow[ProgramID]'/>";
      echo "<tr class='$rowClass'><td><input type='submit' value='Edit'/>";
	  echo "</td><td>".$tblrow['Name']."</td><td>".$tblrow['Year']."</td><td>".$tblrow['Code']."</td><td>".$tblrow['Semester']."</td>";
	  echo "<td>".$tblrow['ApplicationFee']."</td><td>".$tblrow['InterviewFee']."</td><td>".$tblrow['TuitionFee']."</td></tr>";
	  echo "</form>";
    }

    echo '  </tbody>';
    echo '</table>';
    
    endmasterpage();
?>

